/*
 * \brief  Capability representation on Pistachio
 * \author Julian Stecklina
 * \date   2007-12-30
 */

/*
 * Copyright (C) 2007-2009 Julian Stecklina
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__BASE__CAPABILITY_H_
#define _INCLUDE__BASE__CAPABILITY_H_

namespace Pistachio {
#include <l4/types.h>
}

namespace Genode {

	/*
	 * On Pistachio, the local_name member of a capability is global
	 * to the whole system. Therefore, capabilities are to be
	 * created at a central place that prevents id clashes.
	 */
	class Capability
	{
		protected:

			Pistachio::L4_ThreadId_t _tid;
			long                     _local_name;

		public:

			/**
			 * Default constructor
			 */
			Capability() : _local_name (0)
			{
				using namespace Pistachio;
				_tid = L4_nilthread;
			}

			long local_name() const { return _local_name; }

			bool valid() const { return !Pistachio::L4_IsNilThread(_tid); }


			/********************************************************
			 ** Functions to be used by the Pistachio backend only **
			 ********************************************************/

			/**
			 * Creates a L4 capability manually. This must not be called from
			 * generic code.
			 */
			Capability(Pistachio::L4_ThreadId_t tid, long local_name)
			: _tid(tid), _local_name(local_name) { }

			/**
			 * Access raw capability data
			 */
			Pistachio::L4_ThreadId_t tid() const { return _tid; };
	};

	typedef Pistachio::L4_ThreadId_t Connection_state;
}

#endif /* _INCLUDE__BASE__CAPABILITY_H_ */
